var saveOrUpdate;
var reset;
var reload;
var issueParameters;//下发
require(['layout','validator','date','select2'], function () {
	//温度区间
	var $select1 = $("#airCondiLowestTept");
	var list1 = "";
	for(var i=15; i <= 33 ;i++){
		list1+='<option value="'+i+'">'+i+'</option>';
	}
	$select1.html(list1);
	
	//温度区间
	var $select2 = $("#airCondiHighestTept");
	var list2 = "";
	for(var i=33; i >= 15 ;i--){
		list2+='<option value="'+i+'">'+i+'</option>';
	}
	$select2.html(list2);	
	$('#saas').initForm();
	//添加或者更新
	saveOrUpdate = function (fn){
		if($('#vrsnId').val()){
			$.messager.confirm("是否更新", "是否更新该模板信息？", function(r) {
				if (r) {
					if($.validator($('#saas'))){
						var $data = $('#saas').serializeArray();
						$data.push({name:'vrsnType',value:'VERS0007'});
						$data.push({name:'appUpgrade',value:'AIRC0001'});
						$.ajaxExt({
							url : "/airConditioner/updateAirTemplate.htm",
							data : $data
						}).done(function(result){
							fn();
						});
					}
				}});
		}
		else{
			if($.validator($('#saas'))){
				var $data = $('#saas').serializeArray();
				$data.push({name:'vrsnType',value:'VERS0007'});
				$data.push({name:'appUpgrade',value:'AIRC0001'});
				$.ajaxExt({
					url : "/airConditioner/addAirTemplate.htm",
					data : $data
				}).done(function(result){
					fn();
				});
			}
		}		
	}
	
	//重置
	reset=function(reset){
		if($('#vrsnId').val() && reset ==null){
			reload($('#vrsnId').val());
		}
		else{
			$('#saas').reset();
		}		
	}
	
	//重新加载
	reload=function(vrsnId){
		$.ajaxExt({
			url : "/airConditioner/getAirTemplateById.htm",
			data : [{name:'vrsnId',value:vrsnId}]
		}).done(function(data){
			var airData=data;
			$('#saas').setValues(airData);
		});
	}

	issueParameters=function(fn){
		if($.validator($('#saas'))){
			var $data = $('#saas').serializeArray();
			var type = commonFun.getLeftTreeCurrentTreeType();
			var orgIds = commonFun.getLeftTreeCheckedNodes(type);
			$data.push({name:'orgIds',value:orgIds});
			$data.push({name:'vrsnType',value:'VERS0007'});
			$data.push({name:'appUpgrade',value:'AIRC0001'});
			$.ajaxExt({
				url : "/airConditioner/templateAirConditioIssued.htm",
				data : $data
			}).done(function(result){
				fn();
			});
		}
	}
});